package com.ruoyi.common.mybatis;


import com.ruoyi.common.constant.HttpStatus;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

public final class PageResult<T> implements Serializable {

    /**
     * 列表数据
     */
    private List<T> rows;

    /**
     * 总记录数
     */
    private Long total;

    /**
     * 消息状态码
     */
    private int code;

    /**
     * 消息内容
     */
    private String msg;

    public PageResult() {
    }

    public PageResult(List<T> rows, Long total) {
        this.rows = rows;
        this.total = total;
        this.code = HttpStatus.SUCCESS;
        this.msg = "查询成功";
    }

    public PageResult(Long total) {
        this.rows = new ArrayList<>();
        this.total = total;
    }

    public static <T> PageResult<T> empty() {
        return new PageResult<>(0L);
    }

    public static <T> PageResult<T> empty(Long total) {
        return new PageResult<>(total);
    }

    public List<T> getRows() {
        return rows;
    }

    public void setRows(List<T> rows) {
        this.rows = rows;
    }

    public Long getTotal() {
        return total;
    }

    public void setTotal(Long total) {
        this.total = total;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    @Override
    public String toString() {
        return "PageResult{" +
                "rows=" + rows +
                ", total=" + total +
                ", code=" + code +
                ", msg='" + msg + '\'' +
                '}';
    }
}
